/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import db.Redis_Rd;
import db.Redis_W;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import libCore.Util;
import models.U_FriendModel;
import share.ShareMacros;

/**
 *
 * @author LinhTA
 */
public class Friend implements EntityBase {

    public String name;
    public String avata;
    public int gold;
    public int exp;
    public int level;
    public int helpfood;
    public int stealegg;

    public Friend() {
        helpfood    =   0;
        stealegg    =   0;
    }

    public void setDataUser( Map<String, String> obj )
    {
        if (obj != null) 
        {
            name        =   obj.get(ShareMacros.USER_NAME);
            avata       =   obj.get(ShareMacros.USER_AVATA);
            gold        =   Integer.parseInt(obj.get(ShareMacros.GOLD));
            exp         =   Integer.parseInt(obj.get(ShareMacros.EXP));
            level       =   Integer.parseInt(obj.get(ShareMacros.LEVEL));
        }
    }

    @Override
    public Map<String, Object> toAMF() {
        Map<String, Object> data = new HashMap<String, Object>();

        data.put(ShareMacros.USER_AVATA, avata);
        data.put(ShareMacros.USER_NAME, name);
        data.put(ShareMacros.GOLD, gold);
        data.put(ShareMacros.EXP, exp);
        data.put(ShareMacros.LEVEL, level);
        data.put(ShareMacros.HELP_FOOD, helpfood);
        data.put(ShareMacros.STEAL_EGG, stealegg);

        return data;
    }

    @Override
    public void setData( Map<String, Object> obj )
    {
        if (obj != null) 
        {
            name        =   obj.get(ShareMacros.USER_NAME).toString();
            avata       =   obj.get(ShareMacros.USER_AVATA).toString();
            gold        =   Integer.parseInt(obj.get(ShareMacros.GOLD).toString());
            exp         =   Integer.parseInt(obj.get(ShareMacros.EXP).toString());
            level       =   Integer.parseInt(obj.get(ShareMacros.LEVEL).toString());
            helpfood    =   Integer.parseInt(obj.get(ShareMacros.HELP_FOOD).toString());
            stealegg    =   Integer.parseInt(obj.get(ShareMacros.STEAL_EGG).toString());
        }
    }
    
    public void setDataStr( Map<String, String> obj )
    {
        if (obj != null) 
        {
            name        =   obj.get(ShareMacros.USER_NAME);
            avata       =   obj.get(ShareMacros.USER_AVATA);
            gold        =   Integer.parseInt(obj.get(ShareMacros.GOLD));
            exp         =   Integer.parseInt(obj.get(ShareMacros.EXP));
            level       =   Integer.parseInt(obj.get(ShareMacros.LEVEL));
            helpfood    =   Integer.parseInt(String.valueOf(obj.get(ShareMacros.HELP_FOOD)));
            stealegg    =   Integer.parseInt(String.valueOf(obj.get(ShareMacros.STEAL_EGG)));
        }
    }
}